package pri.hillchen.springbootstd.bms.common.base;

import pri.hillchen.springbootstd.bms.entity.system.AccessLog;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Created by hillchen on 2017/10/22.
 */
public class LogHelper {
    private static final int DEQUEUE_SIZE = 500;
    private static ConcurrentLinkedQueue<AccessLog> logQueue = new ConcurrentLinkedQueue<>();
    public static void logEnqueue(AccessLog accessLog){
        logQueue.offer(accessLog);
    }

    public static List<AccessLog> logdequeue(){
        List<AccessLog> accessLogs = new ArrayList<>();
        int currentDequeSize = 0;
        while (currentDequeSize < DEQUEUE_SIZE && !logQueue.isEmpty()){
            accessLogs.add(logQueue.poll());
        }
        return accessLogs;
    }
}
